<!-- 驳回弹框 -->
<template>
    <div>
        <el-dialog v-model="showDialog" title="驳回理由" width="515">
            <el-input v-model="bhtextarea" maxlength="100" placeholder="请输入驳回理由" show-word-limit type="textarea" />
            <div class="flexcenterbox" style="margin-top: 28px">
                <el-button class="my_cancelbtn" @click="onCancel">取消</el-button>
                <el-button class="my_btn" @click="onConfirm">确定</el-button>
            </div>
        </el-dialog>
    </div>
</template>
<script lang="ts" setup>
import { ref, watch } from 'vue'
import {
    ElMessage,
} from 'element-plus'

import { updateOccupationStatus } from '@/api/longInsure/index'
import { longdispatchingagencycheckapi } from '@/api/api'

const props = defineProps({
    show: {
        type: Boolean,
        default: false
    },
    itemDetail: {
        type: Object
    },
    rejectType: {
        type: String,
        default: 'add'
    }
})
const emits = defineEmits(['update:show', 'success'])

const showDialog = ref(false)
const bhtextarea = ref('')

const onConfirm = async () => {
    const query = {
        id: props.itemDetail?.occupationRecord?.id || props.itemDetail?.id,
        status: 2,
        rejectRemark: bhtextarea.value
    }
    if (bhtextarea.value === '') {
        ElMessage.error('请输入驳回理由.')
        return
    }
    if (props.rejectType === 'apply') {
        console.log(1)
        
        await updateOccupationStatus(query)
    } else {
        console.log(2)
        
        await longdispatchingagencycheckapi(query)
    }
    ElMessage.success('驳回成功')
    emits('success')
    onCancel()
}

const onCancel = () => {
    showDialog.value = false
    bhtextarea.value = ''
}

watch(() => props.show, (newval) => {
    showDialog.value = newval
})

watch(showDialog, (newval) => {
    emits('update:show', newval)
})

</script>
<style lang="scss" scoped></style>